//
//  HomePage.m
//  收纳
//
//  Created by  on 2022/10/26.
//

#import "HomePage.h"
#import "HomeCell.h"
#import "ContainerViewController.h"
@interface HomePage()
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@end
@implementation HomePage
- (void)awakeFromNib {
    [super awakeFromNib];
    [self.tableView registerNib:[HomeCell nib] forCellReuseIdentifier:[HomeCell ID]];
}
- (void)setArray:(NSMutableArray<Goods *> *)array{
    _array = array;
    [self.tableView reloadData];
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.array.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomeCell *cell = [tableView dequeueReusableCellWithIdentifier:[HomeCell ID]];
    cell.model = self.array[indexPath.section];
    return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return self.array.count - 1 == section ? 20 : 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section < self.array.count - 1) { return nil; }
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ContainerViewController *vc = [ContainerViewController new];
    vc.model = self.array[indexPath.section];
    [[self currentVC] push:vc :YES];
}
@end

